package com.batchap.photoframe;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

public class MainMIDlet extends MIDlet {

	private boolean closed = false;
	private PhotoFrameCanvas photoFrameCanvas;
	private FrameScreen frameScreenCanvas;
	public Display display;

	public MainMIDlet() {
		display = Display.getDisplay(this);

		photoFrameCanvas = new PhotoFrameCanvas(this);
		photoFrameCanvas.Init();

		frameScreenCanvas = new FrameScreen(this);
		// frameScreenCanvas.Init();
	}

	public void startApp() {
		switchToMenu();
		System.out.println("Start");
	}

	public void switchToMenu() {
		photoFrameCanvas.ReInit();
		//photoFrameCanvas.repaint();
		display.setCurrent(photoFrameCanvas);
		System.out.println("Repaint");
		//photoFrameCanvas.repaint();
		//photoFrameCanvas.paint(g);
	}

	public void switchToFrameScreen(String typeScreen) {
		if (frameScreenCanvas.frameType.equals("")) // lần đầu
		{
			if (typeScreen.equals("kid"))
				frameScreenCanvas.InitFrameType("kid");
			else if (typeScreen.equals("flower"))
				frameScreenCanvas.InitFrameType("flower");
			
			// Init FrameScreen
			frameScreenCanvas.Init();
			System.out.println("Init 1");
		} else {
			if (typeScreen.equals("kid"))
				frameScreenCanvas.InitFrameType("kid");
			else if (typeScreen.equals("flower"))
				frameScreenCanvas.InitFrameType("flower");
			System.out.println("Init 2");
		}

		display.setCurrent(frameScreenCanvas);
	}

	public void pauseApp() {
	}

	public void destroyApp(boolean unconditional) {
		closed = true;
	}

	public void close() {
		destroyApp(true);
		notifyDestroyed();
	}

	public boolean isClosed() {
		return closed;
	}

}
